package com.onpositive.gamemaker.test;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.onpositive.gamemaker.core.GameLevel;
import com.onpositive.gamemaker.swt.SWTGraphicsDevice;
import com.onpositive.gamemaker.visualizer.swt.BasicLevelVisualizer;
import com.onpositive.gamemaker.visualizer.swt.BasicSpriteProvider;

public class GCCreateFrom
{
	public static void main(String[] args)
	{
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Map Example");
		shell.setLayout(new FillLayout());
		shell.setSize(800, 600);

		final BasicSpriteProvider basicProvider = new BasicSpriteProvider();
		final GameLevel gameLevel = TestUtil.createGameLevel(basicProvider);
		basicProvider.setLevel(gameLevel );

		final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND);

		canvas.addPaintListener(new PaintListener()
		{
			public void paintControl(PaintEvent e)
			{
				GC gc = new GC(canvas);
				new BasicLevelVisualizer(new SWTGraphicsDevice(gc), basicProvider).visualizeLevel(gameLevel, 50, 40, e.width, e.height);
				gc.dispose();
			}
		});

		shell.open();
		while (!shell.isDisposed())
		{
			if (!display.readAndDispatch())
			{
				display.sleep();
			}
		}
		display.dispose();
	}
}